package main

import "fmt"

func main() {
	fmt.Println(minNumber([]int{4, 3, 1, 6}, []int{5, 7}))
}

func minNumber(nums1 []int, nums2 []int) int {
	ans := 99
	m1, m2 := make([]int, 10), make([]int, 10)
	for _, n := range nums1 {
		m1[n] = 1
	}
	for _, n := range nums2 {
		if m1[n] == 1 {
			ans = min(ans, n)
		}
		m2[n] = 1
	}

	if ans != 99 {
		return ans
	}

	for n, v := range m1 {
		if v == 1 {
			for n2, v2 := range m2 {
				if v2 == 1 {
					ans = change(n, n2)
					return ans
				}
			}
		}
	}
	return ans
}

func change(a, b int) int {
	if a > b {
		return b*10 + a
	}
	return a*10 + b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
